package cn.mandifal.manager.controller;

import cn.mandifal.advertising.service.AdvertisingCategoryService;
import cn.mandifal.pojo.DpContentCat;
import com.alibaba.dubbo.config.annotation.Reference;
import entity.PageResult;
import entity.Result;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 广告分类控制层
 * @author shun
 */
@RestController
@RequestMapping("/advertisingCategoryController")
public class AdvertisingCategoryController {
    @Reference(timeout = 3000)
    private AdvertisingCategoryService advertisingCategoryService;

    /**
     * 返回全部列表
     * @return
     */
    @RequestMapping("/findAll")
    public List<DpContentCat> findAll(){
        return advertisingCategoryService.findAll();
    }


    /**
     * 查询+分页
     * @param dpContentCat
     * @param pageNum
     * @param pageSize
     * @return
     */
    @RequestMapping("/search")
    public PageResult search(@RequestBody DpContentCat dpContentCat, int pageNum, int pageSize  ){
        return advertisingCategoryService.search(dpContentCat, pageNum, pageSize);
    }

    /**
     * 增加
     * @param dpContentCat
     * @return
     */
    @RequestMapping("/add")
    public Result add(@RequestBody DpContentCat dpContentCat){
        try {
            advertisingCategoryService.add(dpContentCat);
            return Result.success();
        } catch (Exception e) {
            e.printStackTrace();
            return Result.failed();
        }
    }

    /**
     * 修改
     * @param dpContentCat
     * @return
     */
    @RequestMapping("/update")
    public Result update(@RequestBody DpContentCat dpContentCat){
        try {
            advertisingCategoryService.update(dpContentCat);
            return Result.success();
        } catch (Exception e) {
            e.printStackTrace();
            return Result.failed();
        }
    }

    /**
     * 获取实体
     * @param id
     * @return
     */
    @RequestMapping("/findOne")
    public DpContentCat findOne(Long id){
        return advertisingCategoryService.findOne(id);
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @RequestMapping("/delete")
    public Result delete(Long [] ids){
        try {
            advertisingCategoryService.delete(ids);
            return Result.success();
        } catch (Exception e) {
            e.printStackTrace();
            return Result.failed();
        }
    }

}
